#include <string>
#include "atomic.h"
#include "message.h"
#include "mainsimu.h"
#include "strutil.h"
#include "../HeadFile/ERP_FCC_processing_2_model.h"


/**** the Constructor ****/
ERP_FCC_processing_2_model::ERP_FCC_processing_2_model( const string &name)
: Atomic( name )
, ERP_FCC_2_stream_VGO( this->addInputPort( "ERP_FCC_2_stream_VGO") )
, ERP_FCC_2_stream_DO( this->addOutputPort( "ERP_FCC_2_stream_DO") )
, ERP_FCC_2_stream_GASO( this->addOutputPort( "ERP_FCC_2_stream_GASO") )
, ERP_FCC_2_stream_OP( this->addOutputPort( "ERP_FCC_2_stream_OP") )
{

		
	string tmpval1(MainSimulator::Instance().getParameter( this->description(), "ERP_FCC_2_stream_VGO_yield_val" ));
	string tmpval2(MainSimulator::Instance().getParameter( this->description(), "ERP_FCC_2_stream_GASO_yield_val" ));
	string tmpval3(MainSimulator::Instance().getParameter( this->description(), "ERP_FCC_2_stream_DO_yield_val" ));

	ERP_FCC_2_stream_VGO_yield_val = str2float(tmpval1);
	ERP_FCC_2_stream_GASO_yield_val = str2float(tmpval2);
	ERP_FCC_2_stream_DO_yield_val = str2float(tmpval3);
			
		
		
}


/*** the initFunction ***/
Model &ERP_FCC_processing_2_model::initFunction()
{

		
	count = 0;
	delay = "00:00:00:00";
	passivate();
	return *this;
		
		
}

/*** the externalFunction ***/
Model &ERP_FCC_processing_2_model::externalFunction( const ExternalMessage &msg )
{

			
	if( msg.port() == ERP_FCC_2_stream_VGO ){
		ERP_FCC_2_stream_VGO_flowrate = msg.value();
		count = 1;
		holdIn( active, delay);
	}
	return *this;

		
		
}

/*** the internalFunction ***/
Model &ERP_FCC_processing_2_model::internalFunction( const InternalMessage &msg )
{

			
	passivate();
	return *this;
		
		
}

/*** the outputFunction ***/
Model &ERP_FCC_processing_2_model::outputFunction( const InternalMessage &msg )
{

			
	if(count == 1)
	{
		count = 0;
		ERP_FCC_2_stream_DO_flowrate = ERP_FCC_2_stream_VGO_flowrate * ERP_FCC_2_stream_DO_yield_val;
		ERP_FCC_2_stream_GASO_flowrate = ERP_FCC_2_stream_VGO_flowrate * ERP_FCC_2_stream_GASO_yield_val;
		sendOutput( msg.time(), ERP_FCC_2_stream_OP, ERP_FCC_2_stream_VGO_flowrate);
		sendOutput( msg.time(), ERP_FCC_2_stream_DO, ERP_FCC_2_stream_DO_flowrate);
		sendOutput( msg.time(), ERP_FCC_2_stream_GASO, ERP_FCC_2_stream_GASO_flowrate);
	}
	return *this;
		
		
}

